package com.cuit.jifver.weibo.utils;

import android.util.Log;

/**
 * 日志工具
*
* @see : 
* @Copyright : 2011-2088 Chineseall. All Rights Reserved.
* @author : bywyu
* @since：Jdk1.6
* @version : 1.0
* @date : 2011-6-8 下午02:16:41
*
 */
public class LogUtil{
	
	private static final String TAG = "Weibo"; 
	private static final boolean isDug = true;
	private static String[] arr = {"LogUtil"};
	private static final int INFO = 1;
	private static final int DEBUG = INFO + 1;
	private static final int ERROR = DEBUG + 1;
	private static final int WARN = ERROR + 1;
	
	
//	static{
//		System.out.println("test .. ");
//	}
	
	/**
	 * Log.i 打印日志信息
	 * @param o 类文	 
	 * @param msg 打印的日志信内容	 
	 */
	public static void i(Object o,String msg)
	{
		/*if (!isDug)
		{
			return;
		}
		String cName = getClassName(o);
		Log.i(TAG, cName + " " +msg);*/
		showInfo(INFO, msg, o);
	}
	
	public static void i(Class<? extends Object> c,String msg)
	{
		/*if (!isDug)
		{
			return;
		}
		String cName = getClassName(c);
		Log.i(TAG, cName + " " +msg);*/
		showInfo(INFO, msg, c);
	}
	
	/**
	 * Log.d打印日志信息
	 * @param c 类文�?	 * @param msg 打印的日志信�?	 */
	public static void d(Object o,String msg){
		/*if (!isDug)
		{
			return;
		}
		String cName = getClassName(c);
		Log.d(TAG, cName + " " +msg);*/
		showInfo(DEBUG, msg, o);
	}
	
	public static void d(Class<? extends Object> c,String msg){
		/*if (!isDug)
		{
			return;
		}
		String cName = getClassName(c);
		Log.d(TAG, cName + " " +msg);*/
		showInfo(DEBUG, msg, c);
		
	}
	
	public static void e(Object o,String msg)
	{
		/*if (!isDug)
		{
			return;
		}
		String cName = getClassName(c);
		Log.e(TAG, cName + " " +msg);*/
		showInfo(ERROR, msg, o);
	}
	
	public static void e(Class<? extends Object> c,String msg)
	{
		/*if (!isDug)
		{
			return;
		}
		String cName = getClassName(c);
		Log.e(TAG, cName + " " +msg);*/
		showInfo(ERROR, msg, c);
	}
	
	public static void w(Object o,String msg)
	{
		/*if (!isDug)
		{
			return;
		}
		String cName = getClassName(c);
		Log.w(TAG, cName + " " +msg);*/
		showInfo(WARN, msg, o);
	}
	
	public static void w(Class<? extends Object> c,String msg)
	{
		/*if (!isDug)
		{
			return;
		}
		String cName = getClassName(c);
		Log.w(TAG, cName + " " +msg);*/
		showInfo(WARN, msg, c);
	}
	
	/**
	 * 获取文件类名（去除之前的包名)
	 * @param c
	 * @return 类名
	 */
	private static String getClassName(Object o){
		if (o == null)
		{
			return "";
		}
		Class<? extends Object> c = o.getClass();
		return getClassName(c);
	}
	
	private static String getClassName(Class<? extends Object> c)
	{
		if (c == null)
		{
			return "";
		}
		
		String cName = c.getName();
		String[] tmp = cName.split("\\.");
		cName = tmp[tmp.length-1];
		
		return cName;
	}
	
	
	private static boolean compareName(String name)
	{
		
		for (String n:arr)
		{
			if (n.equals(name))
			{
				return true;
			}
		}
		return false;
	}
	
	private static void showInfo(int type, String msg, Object o)
	{
		
		if (!isDug)
		{
			return;
		}
		String cName = getClassName(o);
		msg = cName + " " +msg;
		if (compareName(cName))
		{
			return;
		}
		
		showInfo(type, msg);
		
	}
	
	private static void showInfo(int type, String msg, Class<? extends Object> c)
	{
		if (!isDug)
		{
			return;
		}
		String cName = getClassName(c);
		msg = cName + " " +msg;
		if (compareName(cName))
		{
			return;
		}
		
		showInfo(type, msg);
	}
	
	private static void showInfo(int type, String msg)
	{
		switch (type)
		{
		case INFO:
			Log.i(TAG, msg);
			break;
		case DEBUG:
			Log.d(TAG, msg);
			break;
		case ERROR:
            Log.e(TAG, msg);
			break;
		case WARN:
			Log.w(TAG, msg);
			break;
		}
	}
	
	
}
